def longestSubstr(word):
    """

    :type word: str
    :rtype: str
    """
    length = len(word);
    if length < 2:
        return word;
    else:
        longest = 1;
        index = 0;
        for i in range(0, length - 1):
            for j in range(i+1, length):
                end = word[i:j].find(word[j:j+1]);
                if end == -1:
                    if j == length - 1:
                        longest = length;
                        index = i;
                        break;
                    else:
                        continue;
                else:
                    if j - i > longest - index:
                        longest = j;
                        index = i;
                    break;

            if length - i - 1 <= longest - index:
                break;

        return word[index:longest];
